// const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const Koa = require('koa');
const Router = require('koa-router')
const mongoose = require('mongoose');



// 数据库名
const dbName = 'admin';
// Connection URL
const url = 'mongodb://localhost:27017/' + dbName;


let db = null
let col = null

mongoose.connect(url);
let Schema = mongoose.Schema;
let personSchema = new Schema({
    name: String,
    age: Number,
    sex: {
        type: String,
        default: "男"
    },
    chat: String
});

let personModel = mongoose.model("person",personSchema);

// var x = new Mongo('host[:port]');
// var mydb = x.getDB('mydb');
// var mydb = connect('host[:port]/mydb');

const app = new Koa();

app.use(async ctx => {
    personModel.create([
        {name: "马红灯", age: 19, chat: "红灯1992"},
        {name: "龚志敏", age: 42, chat: "龚1992"},
        {name: "李发华", age: 32, chat: "发华1992"},
        {name: "李建华", age: 22, chat: "建华1992"},
        {name: "依依", age: 22, chat: "依依1992", sex: "女"},
    ], (err) => {
        if(!err) {
            console.log('插入成功')
        } else {
            throw err;
        }
    })
    
});

app.listen(1996);
